<template>
  <div>
    <!-- 按钮 -->
    <div class="btns">
      <el-form size="small" inline style="text-align: center">
        <el-form-item label="名称">
          <el-input v-model="param.name"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-search"
            @click="loadApplications"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
      <div style="text-align:right">
        <el-button size="small" type="primary" icon="el-icon-upload2" @click="downloadHandler">导出</el-button>
        <el-button size="small"  type="primary" icon="el-icon-plus" @click="toAddHandler">新增</el-button>
      </div>
    </div>
    <!-- /按钮 -->
    <!-- 表格 -->
    <el-table size="small" :data="applications">
      <el-table-column label="序号" type="index" :index="1"></el-table-column>
      <el-table-column  label="名称" prop="name"></el-table-column>
       <el-table-column label="类型" prop="type"></el-table-column>
      <el-table-column label="介绍" prop="introduce"></el-table-column>
      <el-table-column label="电话号" prop="telephone"></el-table-column>
      <el-table-column label="email" prop="email"></el-table-column>
       <el-table-column label="创建时间" prop="createTime"></el-table-column>
      <el-table-column label="经度" prop="longitude"></el-table-column>
      <el-table-column label="纬度" prop="latitude"></el-table-column>
      <el-table-column class="el-icon-user-solid" label="用户ID" prop="userId" align="center"></el-table-column>
      <el-table-column label="操作" width="150" align="center">
        <template slot-scope="scope">
         <el-button type="danger" size="mini" icon="el-icon-delete" @click="deleteHandler(scope.row)" circle>删除</el-button>
          <el-button type="primary" size="mini" icon="el-icon-edit"  @click="editHandler(scope.row)" circle>修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
    <!-- 模态框 -->

    <!-- /模态框 -->
  </div>
</template>
<script>
import { del, get } from '@/utils/request'
export default {
  data(){
    return {
      // 参数，用于保存检索的参数
      param:{},
      // 组件模板中需要的数据
      applications:[]
    }
  },
  // 方法或者js的事件处理函数
  methods:{

    downloadHandler(){
      window.location.href = "http://localhost:8888/application/download?name="+this.param.name
    },
    //修改
    editHandler(row){
      //跳转
      this.$router.push({
        path:"/application/create",
        query:row 
      })
    },
    //删除
    deleteHandler(row){
         this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            let url = "http://localhost:8888/application/deleteById"
        del(url,{id:row.id}).then(resp =>{
          this.$message({type:"success",message:resp.message});
          this.loadApplications();
          })
        })
    },
    // 跳转
    toAddHandler(){
      this.$router.push("/application/create")
    },
    // 查询后台中的应用信息
    loadApplications(){
      let url = "http://localhost:8888/application/query"
      get(url,this.param).then(resp => {
        this.applications = resp.data;
      })
    }

  },
  // 页面加载的时候会执行的方法
  created(){
  
    this.loadApplications();
  }
}
</script>
<style scoped>
.btns {
  margin-bottom: 0.5em;
}
</style>